﻿using System;
using Selenium;

namespace Quail
{
    public interface IWebBrowser : IDisposable
    {
        /// <summary>
        /// Gets or sets the number of milliseconds for timeouts (default: 60000)
        /// </summary>
        int Timeout { get; set; }

        /// <summary>
        /// Gets the current ActiveTask for the test
        /// </summary>
        Task ActiveTask { get; }

        /// <summary>
        /// Gets the URL of the current web page
        /// </summary>
        string Location { get; }

        /// <summary>
        /// Gets the location URI.
        /// </summary>
        /// <value>The location URI.</value>
        Uri LocationUri { get; }

        /// <summary>
        /// Gets or sets a value indicating whether successful Browser task are "Rolledback" from the logging system.
        /// </summary>
        bool SilentLogging { get; set; }

        /// <summary>
        /// Returns a disposable object used to cache the current web page location
        /// </summary>
        /// <returns></returns>
        IDisposable CacheLocation();

        /// <summary>
        /// Returns a stopwatch for timeouts
        /// </summary>
        /// <returns>A valid stopwatch</returns>
        TestStopwatch GetStopwatch();

        /// <summary>
        /// Gets or sets the WebPage for the Browser
        /// </summary>
        IWebPage GenericPage { get; set; }

        /// <summary>
        /// Gets the cookie object for the Browser
        /// </summary>
        IWebCookie Cookie { get; }

        /// <summary>
        /// Waits for the specified time
        /// </summary>
        /// <param name="milliseconds">The number of milliseconds to wait</param>
        void Sleep(int milliseconds);

        /// <summary>
        /// Waits for any web page to finish loading
        /// </summary>
        /// <param name="ysod">The type of YSOD check</param>
        void SyncAnyPage(YSODCheckTypes ysod = YSODCheckTypes.CheckForYSOD);

        /// <summary>
        /// Navigates to a url on the current site
        /// </summary>
        /// <param name="url">A url local to the current site</param>
        /// <param name="ysod">The YSOD check flag</param>
        void Navigate(string url, YSODCheckTypes ysod = YSODCheckTypes.CheckForYSOD);

        /// <summary>
        /// Navigates to a url on the current site
        /// </summary>
        /// <param name="url">A url local to the current site</param>
        /// <param name="timeoutTryCounter">Number of times to try to load the page (it'll navigate up to this many times)</param>
        /// <param name="ysodCheck">The YSOD check flag</param>
        void NavigateWithTimeoutRetry(string url, int timeoutTryCounter = 3, YSODCheckTypes ysodCheck = YSODCheckTypes.CheckForYSOD);

        /// <summary>
        /// Setup a function that will modify the url before navigation
        /// </summary>
        /// <param name="func">A function accepting and returning a string (url)</param>
        void SetUrlModification(Func<String, String> func);
        /// <summary>
        /// Gets the Network Traffic Logger (may throw NotImplementedException)
        /// </summary>
        NetworkTraffic NetworkTrafficLogger { get; }

        /// <summary>
        /// Gets an interface to Selenium or a Selenium-like implementation
        /// </summary>
        ISelenium SeleniumInterface { get; }
    }
}
